""""
自定义一个用户账户密码登录程序
1. 使用循环，在输入错误时，让用户持续输入
2. 输入正确时，显示登录成功，并退出循环
3. 如果连续输错达到五次，进行关闭
"""
print("请您先注册账号")
account = (input("请设置您的账户名称："))
password = (input("请设置您的账户密码："))
print("注册成功，请登录")
i = 0
while i < 5:
    account1 = input("请输入您的账户名称：")
    password1 = input("请输入您的账户密码：")
    if account1 == account and password1 == password:
        print("登录成功")
        break
    else:
        print("账号或密码错误，请重新输入")
        i += 1
if i == 5:
    print("您的输入次数已经达到5次，请您在365天后重新输入尝试")


 # 有点好奇 我上面写的代码用图形界面实现会是什么样的？采用了多家AI电子斗蛐蛐于是出来了这个玩意
# import sys
# from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QLineEdit, QPushButton, QVBoxLayout, QHBoxLayout, QFrame, QMessageBox, QStackedWidget
# from PyQt5.QtCore import QPropertyAnimation, QPoint, Qt, QEasingCurve, QTimer
# from PyQt5.QtGui import QIcon, QColor
#
#
# class LoginWindow(QWidget):
#     def __init__(self):
#         super().__init__()
#
#         # 初始化账户信息
#         self.account = ""
#         self.password = ""
#         self.login_attempts = 0
#
#         # 初始化UI
#         self.init_ui()
#
#     def init_ui(self):
#         self.setWindowTitle("注册与登录系统")
#         self.setGeometry(400, 200, 450, 500)  # 调整窗口大小
#         self.setWindowIcon(QIcon("icon.png"))
#         self.setStyleSheet(self.get_style())
#
#         # 注册界面控件
#         self.label_title = self.create_label("欢迎注册", 24, True, "#4CAF50")
#         self.label_account = QLabel("账户名称:", self)
#         self.entry_account = self.create_line_edit("请输入账户名称")
#         self.label_password = QLabel("账户密码:", self)
#         self.entry_password = self.create_line_edit("请输入账户密码", True)
#         self.button_register = self.create_button("注册")
#
#         # 登录界面控件
#         self.label_title_login = self.create_label("欢迎登录", 24, True, "#4CAF50")
#         self.label_title_login.setAlignment(Qt.AlignCenter)
#         self.entry_account_login = self.create_line_edit("请输入账户名称")
#         self.entry_password_login = self.create_line_edit("请输入账户密码", True)
#         self.button_login = self.create_button("登录")
#
#         # 注册布局
#         register_layout = QVBoxLayout()
#         register_layout.addWidget(self.label_title)
#         register_layout.addWidget(self.label_account)
#         register_layout.addWidget(self.entry_account)
#         register_layout.addWidget(self.label_password)
#         register_layout.addWidget(self.entry_password)
#         register_layout.addWidget(self.button_register)
#         register_layout.setSpacing(10)
#
#         # 登录布局
#         login_layout = QVBoxLayout()
#         login_layout.addWidget(self.label_title_login)
#         login_layout.addWidget(self.entry_account_login)
#         login_layout.addWidget(self.entry_password_login)
#         login_layout.addWidget(self.button_login)
#         login_layout.setSpacing(10)
#
#         # StackedWidget 用于注册和登录界面的切换
#         self.stacked_widget = QStackedWidget(self)
#         self.frame_register = QWidget(self)
#         self.frame_register.setLayout(register_layout)
#         self.frame_login = QWidget(self)
#         self.frame_login.setLayout(login_layout)
#
#         # 初始化显示注册界面
#         self.stacked_widget.addWidget(self.frame_register)
#         self.stacked_widget.addWidget(self.frame_login)
#
#         main_layout = QVBoxLayout()
#         main_layout.addWidget(self.stacked_widget)
#         self.setLayout(main_layout)
#
#         # 连接信号与槽
#         self.button_register.clicked.connect(self.register)
#         self.button_login.clicked.connect(self.login)
#
#         # 动画效果延时启动
#         QTimer.singleShot(200, self.animate_title)
#
#     def get_style(self):
#         """返回现代化的QSS样式"""
#         return """
#             QWidget {
#                 background-color: #f9f9f9;
#                 font-family: "Arial", sans-serif;
#             }
#
#             QLabel {
#                 font-size: 22px;
#                 color: #333;
#             }
#
#             QLineEdit {
#                 padding: 10px;
#                 font-size: 16px;
#                 border-radius: 12px;
#                 border: 2px solid #4CAF50;
#                 background-color: #ffffff;
#                 margin-bottom: 15px;
#             }
#
#             QLineEdit:focus {
#                 border-color: #2196F3;
#             }
#
#             QPushButton {
#                 background-color: #4CAF50;
#                 color: white;
#                 padding: 12px;
#                 border-radius: 12px;
#                 font-size: 18px;
#                 transition: background-color 0.3s, transform 0.3s;
#             }
#
#             QPushButton:hover {
#                 background-color: #45a049;
#             }
#
#             QPushButton:pressed {
#                 background-color: #388e3c;
#                 transform: scale(0.98);
#             }
#
#             QFrame {
#                 background-color: #ffffff;
#                 border-radius: 20px;
#                 padding: 30px;
#             }
#         """
#
#     def create_label(self, text, font_size, bold, color):
#         """创建带样式的标签"""
#         label = QLabel(text, self)
#         label.setStyleSheet(f"font-size: {font_size}px; font-weight: {'bold' if bold else 'normal'}; color: {color};")
#         return label
#
#     def create_line_edit(self, placeholder, password=False):
#         """创建带样式的输入框"""
#         line_edit = QLineEdit(self)
#         line_edit.setPlaceholderText(placeholder)
#         line_edit.setStyleSheet("padding: 10px; font-size: 16px; border-radius: 10px; border: 2px solid #4CAF50;")
#         if password:
#             line_edit.setEchoMode(QLineEdit.Password)
#         return line_edit
#
#     def create_button(self, text):
#         """创建带样式的按钮"""
#         button = QPushButton(text, self)
#         button.setStyleSheet("""
#             QPushButton {
#                 background-color: #4CAF50;
#                 color: white;
#                 padding: 12px;
#                 border-radius: 12px;
#                 font-size: 18px;
#                 transition: background-color 0.3s, transform 0.3s;
#             }
#
#             QPushButton:hover {
#                 background-color: #45a049;
#             }
#
#             QPushButton:pressed {
#                 background-color: #388e3c;
#                 transform: scale(0.98);
#             }
#         """)
#         return button
#
#     def register(self):
#         """处理注册逻辑"""
#         self.account = self.entry_account.text()
#         self.password = self.entry_password.text()
#
#         if not self.account or not self.password:
#             self.show_message("输入错误", "账户名称和密码不能为空，请重新输入。", QMessageBox.Warning)
#         else:
#             self.show_message("注册成功", "注册成功，请登录", QMessageBox.Information)
#             self.switch_to_login()
#
#     def login(self):
#         """处理登录逻辑"""
#         account1 = self.entry_account_login.text()
#         password1 = self.entry_password_login.text()
#
#         if not account1 or not password1:
#             self.show_message("输入错误", "账户名称和密码不能为空，请重新输入。", QMessageBox.Warning)
#             return
#
#         if account1 == self.account and password1 == self.password:
#             self.show_message("登录成功", "登录成功", QMessageBox.Information)
#             self.close()
#         else:
#             self.login_attempts += 1
#             if self.login_attempts >= 5:
#                 self.show_message("错误", "连续输错5次，程序已关闭", QMessageBox.Critical)
#                 self.close()
#             else:
#                 self.show_message("账号或密码错误", f"账号或密码错误，请重新输入。剩余尝试次数：{5 - self.login_attempts}", QMessageBox.Warning)
#
#     def switch_to_login(self):
#         """切换到登录界面"""
#         self.stacked_widget.setCurrentIndex(1)  # 切换到登录界面
#
#     def show_message(self, title, text, icon):
#         """显示信息框"""
#         msg = QMessageBox(self)
#         msg.setWindowTitle(title)
#         msg.setText(text)
#         msg.setIcon(icon)
#         msg.exec_()
#
#     def animate_title(self):
#         """标题动画：平滑地移动标题"""
#         animation = QPropertyAnimation(self.label_title, b"pos")
#         animation.setDuration(1000)
#         animation.setStartValue(QPoint(-300, 10))  # 动画开始位置
#         animation.setEndValue(QPoint(150, 10))    # 动画结束位置
#         animation.setEasingCurve(QEasingCurve.InOutQuad)
#         animation.start()
#
#
# if __name__ == '__main__':
#     app = QApplication(sys.argv)
#     window = LoginWindow()
#     window.show()
#     sys.exit(app.exec_())
